/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package montecarloSimple;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;
import java.util.StringTokenizer;

/**
 *
 * @author Antoine
 */
public class ModelSimple {
	
    public double monteCarloStandardOption(String callPutFlag, Double S,Double X,Double T,Double r,Double b,Double v,int nSteps,int nSimulation){
            
    	    Double dt;
    	    Double St ;
    	    Double sum=0.0;
    	    Double drift;
    	    Double vSqrdt;
    	    Double toReturn;
            
    	    int i;
    	    int j;
    	    int z=0;
            
            dt = T / nSteps;
            drift = (b - v*v / 2) * dt;
            vSqrdt = v * Math.sqrt(dt);

            if(callPutFlag.equals("c")){z=1;}
            else if(callPutFlag.equals("p")){z=-1;}
           
            
				            for(i=1;i<=nSimulation;i++){				               
				            	St=S;
				                Random random = new Random();
				                	for(j=1;j<=nSteps;j++){
					                St = St * Math.exp(drift + vSqrdt * random.nextGaussian());
					                }					                
				            sum = sum + Math.max(z*(St-X),0);
				            }
	           
                        
            toReturn=Math.exp(-r*T)*(sum/nSimulation);
            return toReturn;
           } 
    
    
    public static ArrayList<ArrayList> readFile() throws FileNotFoundException, IOException{
        String FILE_NAME = "parameters.csv";

        File file = new File(FILE_NAME);
        StringTokenizer lineParser; 
        BufferedReader reader = new BufferedReader(new FileReader(file));
        ArrayList<ArrayList> dataTable = new ArrayList<ArrayList>(); 
        ArrayList<String> dataRow; 
        String line = null; 
        String value = null;
        
        while ((line = reader.readLine()) != null) { 
            dataRow = new ArrayList<String>(); 
            lineParser = new StringTokenizer(line, ";"); 
            while (lineParser.hasMoreElements()) { 
                value = (String) lineParser.nextElement(); 
                dataRow.add(value); 
            } 
        dataTable.add(dataRow); 
        }
        return dataTable;
    }
    
    
    
    
    
    
    
    
    
    
}
